package activities;

import com.searchparking.R;
import com.searchparking.R.layout;
import com.searchparking.R.menu;

import android.os.Bundle;
import android.os.Trace;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class SearchDirection extends Activity implements OnClickListener {

	private TextView tv_car_parking;
	private EditText ed_location_current;
	private RadioButton radioDirectButton;;
	private ImageView imgview;
	public RadioGroup radioDirectGroup;
	String name_parking, address_destion, address_destion_map;
	String DesAddress;
	Double current_latitude, current_longitude, disten_latitude,
			disten_longitude, disten_latitude_map, disten_longitude_map;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_search_direction);

		Bundle bundle = new Bundle();
		bundle = getIntent().getExtras();
		address_destion_map = bundle.getString("PositionAddress");

		disten_latitude = bundle.getDouble("desLatitude");
		disten_longitude = bundle.getDouble("desLongitude");

		// get location destation on mapview
		disten_latitude_map = bundle.getDouble("DesLatitude");
		disten_longitude_map = bundle.getDouble("DesLongitude");

		Intent i = getIntent();
		// name_parking = i.getStringExtra("Address");
		address_destion = i.getStringExtra("Address");
		initComponent();
		SetOnListener();

	}

	// Get and create control
	public void initComponent() {

		ed_location_current = (EditText) findViewById(R.id.ed_location_current);
		tv_car_parking = (TextView) findViewById(R.id.txt_car_parking_);
		imgview = (ImageView) findViewById(R.id.imgViewDirect);
		radioDirectGroup = (RadioGroup) findViewById(R.id.radioview_direction);
		// Set text for Location
		ed_location_current.setText(MainActivity.address);
		// kiểm tra điều kiện để trả về giá trị
		if (address_destion_map != null) {
			tv_car_parking.setText(address_destion_map);
		} else
			tv_car_parking.setText(address_destion);

		DesAddress = (String) tv_car_parking.getText();

	}

	// set onlistenerv for controll
	public void SetOnListener() {

		imgview.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.imgViewDirect:
			int selectedId = radioDirectGroup.getCheckedRadioButtonId();
			radioDirectButton = (RadioButton) findViewById(selectedId);
			Bundle bundle = new Bundle();
			bundle.putDouble("DeLatitude", disten_latitude);
			bundle.putDouble("DeLongtati", disten_longitude);

			// ---- current map
			bundle.putDouble("DesLatitude_map", disten_latitude_map);
			bundle.putDouble("DesLongitude_map", disten_longitude_map);
			// put address destination
			bundle.putString("DestinationAddress", DesAddress);

			if (selectedId == R.id.rd_map_direction) {

				Toast.makeText(getApplicationContext(),
						radioDirectButton.getText(), Toast.LENGTH_SHORT).show();
				Intent intent_map_direct = new Intent(this,
						MapViewDirection.class);
				intent_map_direct.putExtras(bundle);
				startActivity(intent_map_direct);

			}
			if (selectedId == R.id.rd_list_direction) {
				Toast.makeText(getApplicationContext(),
						radioDirectButton.getText(), Toast.LENGTH_SHORT).show();
				Intent intent_list_direct = new Intent(this,
						DirectionList.class);
				// intent_list_direct.putExtra("Address", address_destion);
				intent_list_direct.putExtras(bundle);
				startActivity(intent_list_direct);
			}
			break;

		}

	}

}
